package com.caucho.hessian.client;


import com.gopay.common.trace.LogConst;
import com.gopay.common.trace.def.Span;
import com.gopay.common.trace.def.Tracer;
import com.gopay.common.trace.enums.TraceType;
import com.gopay.common.trace.helper.LogAbstractHelper;
import com.gopay.common.trace.helper.LogRpcClientHelper;
import com.gopay.common.trace.hessian.HessianHeaderContext;
import com.gopay.common.trace.support.LogContext;
import com.gopay.common.trace.util.SamplingUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Method;
import java.net.URL;

/**
 * 应该是版本的问题 导致hessianProxy的 构造方法 是非public的 所有继承有问题
 * 因此就构建了相同的包来继承
 *
 * @author ddh02
 * @HessanFactory
 * @2017/4/6 21:49  www.gopay.com.cn Inc.All rights reserved.
 */


public class LogHessianProxy extends HessianProxy {

    private LogContext logContext = LogContext.getContext();

    private static final Logger logger = LoggerFactory.getLogger(LogHessianProxy.class);

    public LogHessianProxy(HessianProxyFactory factory, URL url) {
        super(factory, url);
    }


    /**
     * hessian 的方法执行
     * @param proxy
     * @param method
     * @param args
     * @return
     * @throws Throwable
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        LogAbstractHelper helper = new LogRpcClientHelper();

        helper.beforeT(proxy, method, args);

        try {

            return super.invoke(proxy, method, args);

        } catch (Throwable throwable) {
            helper.exT(throwable);
            throw throwable;
        } finally {
            helper.afterT(proxy, method, args);
        }

    }

}
